package com.zzsin.gtestreporter.report;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import java.util.LinkedList;
import java.util.List;

public class Testsuite {

    private List<Testcase> testcaseList = new LinkedList<Testcase>();

    private String name = "";
    private String time = "";
    private String timestamp = "";

    private Node node;

    public Testsuite(Node node){
        this.node = node;
        name = node.getAttributes().getNamedItem("name").getTextContent() + "";
        time = node.getAttributes().getNamedItem("time").getTextContent() + " s";
        timestamp = node.getAttributes().getNamedItem("timestamp").getTextContent() + "";
    }

    public int parse(){
        NodeList nodeList = this.node.getChildNodes();
        for(int i=0; i<nodeList.getLength(); i++) {
            Node node = nodeList.item(i);
            if(!node.getNodeName().equals("testcase")){
                continue;
            }
            Testcase testcase = new Testcase(node);
            testcaseList.add(testcase);
        }
        return 0;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public String getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(String timestamp) {
        this.timestamp = timestamp;
    }

    public List<Testcase> getTestcaseList() {
        return testcaseList;
    }

    public void setTestcaseList(List<Testcase> testcaseList) {
        this.testcaseList = testcaseList;
    }
}
